<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Catch</title>
</head>
<body>
    <h1>Catch</h1>
    <script>
        const p1 = new Promise((resolve, reject) => {
            setTimeout( () => {
                console.log('detail p1');
                reject(new Error('fail'));
            }, 3000);
        });

        const p2 = new Promise((resolve, reject) => {
            setTimeout( () => {
                console.log('detail p2');
                resolve(p1)
            }, 2000);
        });

        p2.then(res => {
            console.log(res);
        })
        .catch(err => {
            console.log(err);  
        });
    </script>
</body>
</html>